<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org" th:with="tit='图书信息管理'">

<head th:replace="header::headFregment(${tit})">
</head>
<body>
<div th:replace="header::header"></div>
<div th:replace="header::nav"></div>

<div class="content">
    <div class="container-fluid">
        <div class="row-fluid">
            <blockquote>
                <p style="font-size: 24px;margin: 20px">图书信息添加</p>
            </blockquote>

            <form class="form-horizontal" id="addform">
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">书本编号:</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="bnum" id="bnum"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">书名:</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="bname" id="bname"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">作者：</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="bauthor" id="bauthor"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">出版社：</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="bpress" id="bpress"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">价格：</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="bprice" id="bprice"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">类目：</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="btype" id="btype"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">书本总量：</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="bsnum" id="bsnum"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">借出数量：</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="bloan" id="bloan"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">剩余数量：</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="bres" id="bres"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2">所在位置（柜号）：</label>
                    <div class="col-lg-10"><input type="text" class="form-control" name="blocation" id="blocation"></div>
                </div>
                <div class="form-group" style="margin-top: 20px">
                    <label class="control-label col-lg-2"></label>
                    <div class="col-lg-10"><button type="button" class="btn btn-primary"  id="addbtn">确认添加</button></div>
                </div>
            </form>
        </div>
    </div>
    <div class="container-fluid">
        <div class="row-fluid">
            <footer th:replace="footer::footer"></footer>
        </div>
    </div>
</div>

</body>
</html>
<script>
    $("#addbtn").click(function () {
        $.ajax({
            url:'/doAddBok',
            type:'post',
            data:$("#addform").serialize(),
            success:function (result) {
                if (result.res=='success'){
                    alert("添加成功！");
                    location.href="/index";
                } else {
                    if (result.res=='had'){
                        alert("学号已存在！");
                    }else{
                        alert("添加失败！");
                    }
                }
            },
            error:function () {
                alert("通讯失败！");
            }
        });
    });
</script>